import { createRouter, createWebHistory } from 'vue-router'
import LoginPage from '@/views/LoginPage.vue'
import MainPage from '@/views/MainPage/MainPage.vue'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/login',
            component: LoginPage,
        },
        {
            path: '/',
            component: MainPage,
        },
        {
            path: '/test',
            component: () => import('@/views/Test/TestPage.vue'),
        },
        {
            path: '/:pathMatch(.*)*', //匹配所有路由 404页面
            component: () => import('@/components/NoteFound.vue'),
        },
    ],
})

//每次路由跳转之前触发
// router.beforeEach((to, from, next) => {
//    // const store = useCategoryStore()
//     if (to.path === '/login') {
//         next()
//     } else {
//         if (!localStorage.getItem('token')) {
//             //如果没有token，就跳转到登录页面
//             next('/login')
//         }
//     }
// })

export default router
